﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dream
{
    class Program
    {
        static void Main(string[] args)
        {
            
        }
        //用户输入正方形边长，用*打印出实心正方形。
        public static void Text()
        {
            int[,] arr = new int[5, 5];
            Console.WriteLine("请输入正方形的边长");
            int a = int.Parse(Console.ReadLine());
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }
        //九九乘法表 规则数组
        public static void Text2()
        {
            string[,] arr = new string[9, 9];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    arr[i, j] = (i + 1) + " * " + (j + 1) + " = " + (i + 1) * (j + 1) + " \t ";
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j]);
                }
                Console.WriteLine();
            }
        }
        //用户输入正方形边长，用*打印出空心正方形。
        public static void Text3()
        {
            string[,] arr = new string[5, 5];
            Console.WriteLine("请输入正方形的边长");
            int b = int.Parse(Console.ReadLine());
            for (int i = 1; i <= arr.GetLength(0); i++)
            {
                for (int j = 1; j <= arr.GetLength(1); j++)
                {
                    if (i == 1 || i == b || j == 1 || j == b)
                    {
                        Console.Write("*");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }
        }
        //打印凌形
        public static void Text4()
        {
            Console.WriteLine("请输入菱形的边长");
            int c = int.Parse(Console.ReadLine());
            string[,] arr = new string[2 * c - 1 , 2 * c - 1];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    if (i < c)
                    {
                        if (j >= c - 1 - i && j <= c - 1 + i)
                        {
                            arr[i, j] = "*";
                        }
                        else
                        {
                            arr[i, j] = " ";
                        }
                    }
                    else
                    {
                        arr[i, j] = arr[c * 2 - 1 - i - 1, j];
                    }
                }
            }

            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    Console.Write(arr[i, j]);
                }
            Console.WriteLine();
            }
        }
        //如果一个数组保存元素是有序的（从大到小），向这个数组中插入一个数，使得插入后的数组元素仍然保持有序。
        public static void Text5() 
        {
            int[] arr = { 5,8,10,6,3};
            int[] brr = new int[arr.Length+1];
            Console.WriteLine("排序前：");
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i] + "||");
            }
            Console.WriteLine();
            Console.WriteLine("请输入要插入的一个数");
            int d = int.Parse(Console.ReadLine());
            for (int i = 0; i < brr.Length; i++)
            {
                if (i >= arr.Length)
                {
                    brr[i] = d;
                }
                else {
                    brr[i] = arr[i];
                }
            }
            Array.Sort(brr);
            Array.Reverse(brr);
            Console.WriteLine("排序后：");
            for (int i = 0; i < brr.Length; i++)
            {
                Console.Write(brr[i] + "||");
            }
            Console.WriteLine();

        }
        //在 Main 方法中创建一个字符串类型的数组，并存入 5 个值，然后将数组中下标是偶数的元素输出。
        public static void Text6() 
        {
            string[] arr = { "5", "8", "10", "15", "17" };
            Console.WriteLine("下标是偶数");
            for (int i = 0; i < arr.Length; i++)
            {
                if (i % 2 == 0)
                {
                    Console.WriteLine(arr[i] + " ");
                }
            }
            Console.WriteLine();
        }
        //打印杨辉三角形
        public static void Text7() 
        {
            Console.WriteLine("请输入要打印的行数");
            int yan = int.Parse(Console.ReadLine());
            int[,] arr = new int[yan, yan];
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    if (j==0 || j == i)
                    {
                        arr[i, j] = 1;
                    }
                    else
                    {
                        arr[i, j] = arr[i -1, j] + arr[i-1, j - 1];
                    }
                }
            }
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                for (int j = 0; j < arr.GetLength(1); j++)
                {
                    if (arr[i,j] != 0)
                    {
                        Console.Write(arr[i, j].ToString() + "\t");
                    }
                }
            Console.WriteLine();
            }
        }
    }
}